package com.misolab.utility.speedmate.util;

import java.lang.reflect.Method;

import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

public class MyWindowManager {

	private static String TAG = "IWindowManager";
	private final Object mIWindowManager;
	
	public MyWindowManager() {
		
		Object iWindowManager = null;
		try {
			Class<?> serviceManagerClass = Class
					.forName("android.os.ServiceManager");
			Method getService = serviceManagerClass.getDeclaredMethod(
					"getService", String.class);
			iWindowManager = getService.invoke(null, "window");

			Class<?> wmClassStub = Class
					.forName("android.view.IWindowManager$Stub");
			Method asInterface = wmClassStub.getDeclaredMethod("asInterface",
					IBinder.class);
			iWindowManager = asInterface.invoke(null, (IBinder) iWindowManager);
		} catch (Exception e) {
			Log.e(TAG, e.toString(), e);
		}
		mIWindowManager = iWindowManager;
	}

	public void setAnimationScale(int which, float scale) throws RemoteException {
		
		try {
			Method declaredMethod = mIWindowManager.getClass().getDeclaredMethod("setAnimationScale", int.class, float.class);
			declaredMethod.invoke(mIWindowManager, which, scale);
		} catch (Exception e) {
			Log.e(TAG, e.toString(), e);
		}
	}

	public float getAnimationScale(int which) throws RemoteException {
		
		try {
			Method declaredMethod = mIWindowManager.getClass().getDeclaredMethod("getAnimationScale", int.class);
			return (Float)declaredMethod.invoke(mIWindowManager, which);
		} catch (Exception e) {
			Log.e(TAG, e.toString(), e);
		}
		return 0.0f;
	}
}
